#include "watting.h"

Watting::Watting()
{
    setupUi(this);
    this->setGeometry(400,200,468, 286);
    this->setWindowTitle(tr("登录"));
    this->setWindowFlags(Qt::FramelessWindowHint);
    //窗体透明化
    this->setAttribute(Qt::WA_TranslucentBackground, true);
    this->setWindowOpacity(0.9);
    label->setStyleSheet("QLabel{border:0px;background-image:url(:/bg6.png);}");
    QPixmap s1("./mini.png");
    miniButton->setIcon(s1);
    miniButton->setStyleSheet("QPushButton{border-radius:10px;border:0px}");
    miniButton->setFlat(true);
    QPixmap s2("./close.png");
    closeButton->setIcon(s2);
    closeButton->setStyleSheet("QPushButton{border-radius:10px;border:0px}");
    progressBar->setValue(0);
    timeCounter=0;
    timer.start(1000);
    connect(miniButton,SIGNAL(clicked()),this,SLOT(showMinimized()));
    connect(closeButton,SIGNAL(clicked()),this,SLOT(close()));
    connect(&timer,SIGNAL(timeout()),this,SLOT(timerClick()));
}

void Watting::closeEvent(QCloseEvent *event)
{
}

void Watting::mousePressEvent(QMouseEvent * event)
{
    if (event->button() == Qt::LeftButton) //点击左边鼠标
    {
         dragPosition = event->globalPos() - frameGeometry().topLeft();
         //globalPos()获取根窗口的相对路径，frameGeometry().topLeft()获取主窗口左上角的位置
         event->accept();   //鼠标事件被系统接收
    }
    if (event->button() == Qt::RightButton)
    {
         close();
    }
}

void Watting::mouseMoveEvent(QMouseEvent * event)
{
    if (event->buttons() == Qt::LeftButton) //当满足鼠标左键被点击时。
    {
         move(event->globalPos() - dragPosition);//移动窗口
         event->accept();
    }
}
void Watting::timerClick()
{
    if(++timeCounter==15)
        timeCounter==0;
    int tmp=100/15*timeCounter;
    if (tmp<=100)
        progressBar->setValue(tmp);
    else
        progressBar->setValue(100);
}
void Watting::startWait()
{
    timeCounter=0;
    timer.start(1000);
}
void Watting::toHide()
{    
    progressBar->setValue(0);
    timeCounter=0;
    timer.stop();
    this->hide();
}
